#include "homepage.h"
#include "ui_homepage.h"
#include <QColor>
#include <QFont>
#include <QString>
#include "mqtthandler.h"
#include "globalval.h"
#include <QDebug>





HomePage::HomePage(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::HomePage)
{
    ui->setupUi(this);

   setWindowTitle("智能农业");
   setWindowIcon(QIcon("://image/pQString HomePage::ip; // 定义静态成员变量，默认初始化为空字符串1.png"));
   setFixedSize(1000,600);
    //ui->listWidget->setStyleSheet("background-color: #000000; color: white;\
                                border: 2px solid black; border-radius: 5px;");

    ui->listWidget->setStyleSheet(
        "QListWidget {"
        "    background-color: #A9A9A9;"   // 列表背景色
        "    border: 1px solid #d0d0d0;" // 边框
        "}"
        "QListWidget::item {"
        "    height: 30px;"             // 每项高度
        "    padding: 5px;"             // 内边距
        "}"
        "QListWidget::item:hover {"
        "    background-color: #f0f0f0;" // 悬停背景
        "}"
        "QListWidget::item:selected {"
        "    background-color: #696969;" // 选中背景
        "    color: white;"             // 选中文字
        "}"
    );

    ui->listWidget->setFixedSize(200, this->frameGeometry().height());
    ui->listWidget->addItem("m0");
    ui->listWidget->addItem("场景");
    ui->listWidget->addItem("监控");
    ui->listWidget->addItem("设备搜索");
    ui->listWidget->addItem("设置");


    //实例化四个界面
    m0Wig = new M0Wig;
    modbusWig = new ModbusWig;
    mbappWig = new MbappWig;
    devwight =new devWight;
    setWig = new SetWig;



    //将四个界面依次添加到堆栈窗体
    ui->stackedWidget->addWidget(m0Wig);
    ui->stackedWidget->addWidget(modbusWig);
    ui->stackedWidget->addWidget(mbappWig);
    ui->stackedWidget->addWidget(devwight);
    ui->stackedWidget->addWidget(setWig);




    //连接列表界面和堆栈窗体的信号
    QObject::connect(ui->listWidget, SIGNAL(currentRowChanged(int)),
                     ui->stackedWidget, SLOT(setCurrentIndex(int)));

    //哪个界面需要接收mqtt的消息，就订阅这个信号，然后再自己的界面文件中处理消息
    //Qobject::connect(mqtt,SIGNAL(dataUPSignal(QByteArray)),\
                     modbusWig,SLOT(dataUPSlot((QByteArray)));

    MqttHandler *mqtt =new MqttHandler;
    GlobalVal:: mqtt = mqtt;
    QObject ::connect(mqtt,&MqttHandler::connect_ok,devwight,&devWight::connectok_slots);
    QObject ::connect(mqtt,&MqttHandler::dataUpSignal,modbusWig,&ModbusWig::parse);
    QObject ::connect(mqtt,&MqttHandler::dataUpSignal,m0Wig,&M0Wig::m0msg);

}

HomePage::~HomePage()
{
    delete ui;
}



